const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require("clean-webpack-plugin");
module.exports = {
  devtool: 'eval-source-map',
  entry:  __dirname + "/src/index.js",//已多次提及的唯一入口文件
  output: {
    path: __dirname + "/dist",//打包后的文件存放的地方
    filename: "bundle-[hash].js"//打包后输出文件的文件名
  },
  devServer: {
    contentBase: "./public",//本地服务器所加载的页面所在的目录
    historyApiFallback: true,//不跳转
    inline: true,//实时刷新
    disableHostCheck: true
  },
  module: {
    rules: [
      {
        test: /(\.jsx|\.js)$/,
        use: [{
          loader: "babel-loader",
        },{
          loader: "eslint-loader"
        }],
        exclude: /node_modules/
      }
    ]
  },
  plugins: [
    // index.html模板
    new HtmlWebpackPlugin({
      template: __dirname + "/src/index.html",
      filename: 'index.html',
      inject: 'body'
    }),
    new CleanWebpackPlugin('dist/*.*', {
      root: __dirname,
      verbose: true,
      dry: false
    }),
    // 删除警告
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': '"production"',
    }),
    // 压缩js文件
    new webpack.optimize.UglifyJsPlugin(),
  ]
}
